package com.yjy.xml.v1;

import com.alibaba.fastjson.JSON;
import com.yjy.xml.JaxbXmlUtil;

// 测试xml与bean互转
public class MainTest {

    public static void main(String[] args) throws Exception {
        // xml转bean（泛型）
        String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Message><Head><ReqJnlNo>1470717970464</ReqJnlNo><ResJnlNo>136601</ResJnlNo><ResTime>20160809124612</ResTime><ResCode>000000</ResCode><ResMsg>交易处理成功</ResMsg></Head><Body><UserType>A00000002101</UserType><Status>A00000002101</Status><TransInfoList><TransInfoMap><VirlAcctName>A00000002101</VirlAcctName><VirlAcctNo>A00000002101</VirlAcctNo><CifNo>A000000021</CifNo><VirlAcctType>01</VirlAcctType></TransInfoMap><TransInfoMap><VirlAcctName>A00000002101</VirlAcctName><VirlAcctNo>A00000002101</VirlAcctNo><CifNo>A000000021</CifNo><VirlAcctType>01</VirlAcctType></TransInfoMap></TransInfoList></Body></Message>";
        CbhbRspTransaction<OpenAcctRsp_cbhb> cbhbRspTransaction = JaxbXmlUtil.xmlToBean(xml, CbhbRspTransaction.class, OpenAcctRsp_cbhb.class);
        System.out.println(JSON.toJSONString(cbhbRspTransaction));

        // bean转xml（泛型）
        String bean2xml = JaxbXmlUtil.beanToXml(cbhbRspTransaction, OpenAcctRsp_cbhb.class);
        System.out.println(bean2xml);

        // bean转xml（无泛型）
        OpenAcctRsp_cbhb mainData = cbhbRspTransaction.getMainData();
        String mainDataStr = JaxbXmlUtil.beanToXml(mainData);
        System.out.println(mainDataStr);

        // xml转bean（无泛型）
        OpenAcctRsp_cbhb openAcctRsp_cbhb = JaxbXmlUtil.xmlToBean(mainDataStr, OpenAcctRsp_cbhb.class);
        System.out.println(JSON.toJSONString(openAcctRsp_cbhb));
    }
}
